﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace AMDev.BNET.ClientAPI
{
    public static class RegionsEnumerationExtensions
    {
        public static String GetHost(this RegionsEnumeration value)
        {
            String host = null;
            BNETRegionHostAttribute[] hostAttributes = null;
            
            Type enumType = null;
            FieldInfo fieldInfo = null;
            
            enumType = typeof(RegionsEnumeration);
            fieldInfo = enumType.GetField(value.ToString());
            hostAttributes = fieldInfo.GetCustomAttributes(typeof(BNETRegionHostAttribute), false) as BNETRegionHostAttribute[];
            if (hostAttributes != null)
                host = hostAttributes.FirstOrDefault().Hostname;
            return host;
        }

        public static String GetRegion(this RegionsEnumeration value)
        {
            String host = null;
            BNETRegionHostAttribute[] hostAttributes = null;

            Type enumType = null;
            FieldInfo fieldInfo = null;

            enumType = typeof(RegionsEnumeration);
            fieldInfo = enumType.GetField(value.ToString());
            hostAttributes = fieldInfo.GetCustomAttributes(typeof(BNETRegionHostAttribute), false) as BNETRegionHostAttribute[];
            if (hostAttributes != null)
                host = hostAttributes.FirstOrDefault().Region;
            return host;
        }
    }
}
